package dynamicprogramming.杨辉三角;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    public List<List<Integer>> generate(int numRows) {
        /**
         * f[i][j] = f[i-1][j-1] + f[i-1][j]
         * 初始值都是1
         */
        List<List<Integer>> ans = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            List<Integer> current = new ArrayList<>();
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    current.add(1);
                } else {
                    List<Integer> prevRow = ans.get(i - 1);
                    current.add(prevRow.get(j) + prevRow.get(j - 1));
                }
            }
            ans.add(current);
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.generate(5));
    }
}
